package cn.com.sd.system.dao.hibernate;

import java.util.List;

import org.springframework.stereotype.Component;

import cn.com.sd.common.util.MyStringUtils;
import cn.com.sd.common.util.Page;
import cn.com.sd.system.dao.IRoleDAO;
import cn.com.sd.system.model.Role;

@SuppressWarnings("unchecked")
@Component(value = "roleDAO")
public class RoleDAOHibernate extends BaseDAOHibernate<Role> implements IRoleDAO{
	
	@Override
	public List<Role> getRoleList(Page page) {
		List<Role> roles = createQuery("from Role").setFirstResult(page.getStartRow()).setMaxResults(page.getStartRow() + page.getPageSize()).list();
		return roles;
	}
	
	@Override
	public Integer getRoleCount() {
		String hql = "select count(role.id) from Role role";
		Long count = (Long) findUnique(hql);
		return MyStringUtils.translateLongToInteger(count);
	}
}
